export default function canvasToFile(
  canvas: HTMLCanvasElement,
  filename: string
) {
  const dataurl = canvas.toDataURL("image/png");
  console.log(dataurl);

  //base64 转 File
  const arr: any = dataurl.split(",");
  console.log(arr);
  const mime = arr[0].match(/:(.*?);/)[1];
  console.log(mime);
  const bstr = atob(arr[1]);
  console.log(bstr);
  let n = bstr.length;
  const u8arr = new Uint8Array(n);
  while (n--) {
    u8arr[n] = bstr.charCodeAt(n);
  }
  console.log(u8arr);

  const file = new File([u8arr], filename, { type: mime });
  console.log(file);
  return file;
}
